﻿using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbVisibilityOverrule : OdRxOverrule
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbVisibilityOverrule(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbVisibilityOverrule_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbVisibilityOverrule obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbVisibilityOverrule()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbVisibilityOverrule(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public OdDbVisibilityOverrule() : this(TD_DbPINVOKE.new_OdDbVisibilityOverrule(), MemoryManager.GetMemoryManager().GetCurrentTransaction() == null)
		{
			MemoryTransaction currentTransaction = MemoryManager.GetMemoryManager().GetCurrentTransaction();
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbVisibilityOverrule(this.swigCPtr.Handle, true));
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			this.SwigDirectorConnect();
		}

		public new static OdDbVisibilityOverrule cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbVisibilityOverrule_cast(OdRxObject.getCPtr(pObj));
			OdDbVisibilityOverrule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbVisibilityOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbVisibilityOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbVisibilityOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbVisibilityOverrule_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(this.SwigDerivedClassHasMethod("isA", OdDbVisibilityOverrule.swigMethodTypes1) ? TD_DbPINVOKE.OdDbVisibilityOverrule_isASwigExplicitOdDbVisibilityOverrule(this.swigCPtr) : TD_DbPINVOKE.OdDbVisibilityOverrule_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(this.SwigDerivedClassHasMethod("queryX", OdDbVisibilityOverrule.swigMethodTypes0) ? TD_DbPINVOKE.OdDbVisibilityOverrule_queryXSwigExplicitOdDbVisibilityOverrule(this.swigCPtr, OdRxClass.getCPtr(protocolClass)) : TD_DbPINVOKE.OdDbVisibilityOverrule_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdDbVisibilityOverrule createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbVisibilityOverrule_createObject();
			OdDbVisibilityOverrule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbVisibilityOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbVisibilityOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbVisibilityOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual Visibility visibility(OdDbEntity pSubject)
		{
			Visibility result = (Visibility)(this.SwigDerivedClassHasMethod("visibility", OdDbVisibilityOverrule.swigMethodTypes3) ? TD_DbPINVOKE.OdDbVisibilityOverrule_visibilitySwigExplicitOdDbVisibilityOverrule(this.swigCPtr, OdDbEntity.getCPtr(pSubject)) : TD_DbPINVOKE.OdDbVisibilityOverrule_visibility(this.swigCPtr, OdDbEntity.getCPtr(pSubject)));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult setVisibility(OdDbEntity pSubject, Visibility visibility, bool doSubents)
		{
			OdResult result = (OdResult)(this.SwigDerivedClassHasMethod("setVisibility", OdDbVisibilityOverrule.swigMethodTypes4) ? TD_DbPINVOKE.OdDbVisibilityOverrule_setVisibilitySwigExplicitOdDbVisibilityOverrule__SWIG_0(this.swigCPtr, OdDbEntity.getCPtr(pSubject), (int)visibility, doSubents) : TD_DbPINVOKE.OdDbVisibilityOverrule_setVisibility__SWIG_0(this.swigCPtr, OdDbEntity.getCPtr(pSubject), (int)visibility, doSubents));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult setVisibility(OdDbEntity pSubject, Visibility visibility)
		{
			OdResult result = (OdResult)(this.SwigDerivedClassHasMethod("setVisibility", OdDbVisibilityOverrule.swigMethodTypes5) ? TD_DbPINVOKE.OdDbVisibilityOverrule_setVisibilitySwigExplicitOdDbVisibilityOverrule__SWIG_1(this.swigCPtr, OdDbEntity.getCPtr(pSubject), (int)visibility) : TD_DbPINVOKE.OdDbVisibilityOverrule_setVisibility__SWIG_1(this.swigCPtr, OdDbEntity.getCPtr(pSubject), (int)visibility));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private void SwigDirectorConnect()
		{
			if (this.SwigDerivedClassHasMethod("queryX", OdDbVisibilityOverrule.swigMethodTypes0))
			{
				this.swigDelegate0 = new OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_0(this.SwigDirectorqueryX);
			}
			if (this.SwigDerivedClassHasMethod("isA", OdDbVisibilityOverrule.swigMethodTypes1))
			{
				this.swigDelegate1 = new OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_1(this.SwigDirectorisA);
			}
			if (this.SwigDerivedClassHasMethod("isApplicable", OdDbVisibilityOverrule.swigMethodTypes2))
			{
				this.swigDelegate2 = new OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_2(this.SwigDirectorisApplicable);
			}
			if (this.SwigDerivedClassHasMethod("visibility", OdDbVisibilityOverrule.swigMethodTypes3))
			{
				this.swigDelegate3 = new OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_3(this.SwigDirectorvisibility);
			}
			if (this.SwigDerivedClassHasMethod("setVisibility", OdDbVisibilityOverrule.swigMethodTypes4))
			{
				this.swigDelegate4 = new OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_4(this.SwigDirectorsetVisibility__SWIG_0);
			}
			if (this.SwigDerivedClassHasMethod("setVisibility", OdDbVisibilityOverrule.swigMethodTypes5))
			{
				this.swigDelegate5 = new OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_5(this.SwigDirectorsetVisibility__SWIG_1);
			}
			TD_DbPINVOKE.OdDbVisibilityOverrule_director_connect(this.swigCPtr, this.swigDelegate0, this.swigDelegate1, this.swigDelegate2, this.swigDelegate3, this.swigDelegate4, this.swigDelegate5);
		}

		private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes)
		{
			MethodInfo method = base.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, methodTypes, null);
			return method.DeclaringType.IsSubclassOf(typeof(OdDbVisibilityOverrule));
		}

		private IntPtr SwigDirectorqueryX(IntPtr protocolClass)
		{
			return OdRxObject.getCPtr(this.queryX((OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(protocolClass, false))).Handle;
		}

		private IntPtr SwigDirectorisA()
		{
			return OdRxClass.getCPtr(this.isA()).Handle;
		}

		private bool SwigDirectorisApplicable(IntPtr pOverruledSubject)
		{
			return this.isApplicable(Teigha.Core.Helpers.odrxCreateObjectInternal(pOverruledSubject, false));
		}

		private int SwigDirectorvisibility(IntPtr pSubject)
		{
			return (int)this.visibility((OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(pSubject, false));
		}

		private int SwigDirectorsetVisibility__SWIG_0(IntPtr pSubject, int visibility, bool doSubents)
		{
			return (int)this.setVisibility((OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(pSubject, false), (Visibility)visibility, doSubents);
		}

		private int SwigDirectorsetVisibility__SWIG_1(IntPtr pSubject, int visibility)
		{
			return (int)this.setVisibility((OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(pSubject, false), (Visibility)visibility);
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		private OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_0 swigDelegate0;

		private OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_1 swigDelegate1;

		private OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_2 swigDelegate2;

		private OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_3 swigDelegate3;

		private OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_4 swigDelegate4;

		private OdDbVisibilityOverrule.SwigDelegateOdDbVisibilityOverrule_5 swigDelegate5;

		private static Type[] swigMethodTypes0 = new Type[]
		{
			typeof(OdRxClass)
		};

		private static Type[] swigMethodTypes1 = new Type[0];

		private static Type[] swigMethodTypes2 = new Type[]
		{
			typeof(OdRxObject)
		};

		private static Type[] swigMethodTypes3 = new Type[]
		{
			typeof(OdDbEntity)
		};

		private static Type[] swigMethodTypes4 = new Type[]
		{
			typeof(OdDbEntity),
			typeof(Visibility),
			typeof(bool)
		};

		private static Type[] swigMethodTypes5 = new Type[]
		{
			typeof(OdDbEntity),
			typeof(Visibility)
		};

		public delegate IntPtr SwigDelegateOdDbVisibilityOverrule_0(IntPtr protocolClass);

		public delegate IntPtr SwigDelegateOdDbVisibilityOverrule_1();

		public delegate bool SwigDelegateOdDbVisibilityOverrule_2(IntPtr pOverruledSubject);

		public delegate int SwigDelegateOdDbVisibilityOverrule_3(IntPtr pSubject);

		public delegate int SwigDelegateOdDbVisibilityOverrule_4(IntPtr pSubject, int visibility, bool doSubents);

		public delegate int SwigDelegateOdDbVisibilityOverrule_5(IntPtr pSubject, int visibility);
	}
}
